package app.caihan.scframe.ktx.lifecycle

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import app.caihan.scframe.livedata.BooleanLiveData

/**
 * 应用前后台切换
 * ProcessLifecycleOwner.get().lifecycle.addObserver(KtxAppLifeObserver)
 *
 * @author Seven-C
 * @date 2020/7/27
 */
object AppLifeObserverKtx : LifecycleObserver {

    private var isForeground = BooleanLiveData()

    //在前台
    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    private  fun onForeground() {
        isForeground.value = true
    }

    //在后台
    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    private fun onBackground() {
        isForeground.value = false
    }

}